********************************************************************************
*																			   *
*						Sir! I'd Rather Go to School Sir!					   *
*																			   *
*								 Mahdi Majbouri								   *
*																			   *
*									Table A2-A5								   *
*																			   *
*									6-6-2023								   *
*																			   *
********************************************************************************

********************************************************************************
**  Test for discontinuity in the number of observations
********************************************************************************

use "census11-all.dta", clear

keep if fage>=fage18 & fage18>=threshold - 9 & fage18<=threshold + 10 & ///
		father_ed !=. & mom_ed != . & fage !=. & mage !=.

keep if relate == 3 & son == 1 & sons == 1 & urban == 2


********* FIGURE A2 *********

sort fa
by fa: egen fed = mean(father_ed) if relate==3 & son==1 & sons == 1 & fage>=fage18 & urban == 2 & college_plus !=. & father_ed != . & mom_ed != .& mage !=.
egen mfed = tag(fed)

twoway ///
(scatter fed fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & urban == 2, mcolor(gs3) ) ///
(lfitci father_ed fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==1 & urban == 2,fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lfitci father_ed fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==0 & urban == 2, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) xtitle("Age of the Sole Son's Father") ///
		ytitle("Father's Education Level") title("Linear fit")  note("") saving("fedl.eps", replace)
		
twoway ///
(scatter fed fage18, mcolor(gs3)) ///
(qfitci father_ed fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(qfitci father_ed fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Father's Education Level") ///
	title("Quadratic fit")  note("") saving("fedq.eps", ///
	replace)

twoway ///
(scatter fed fage18, mcolor(gs3)) ///
(lpolyci father_ed fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lpolyci father_ed fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Father's Education Level") ///
	title("Polynomial fit")  note("") saving("fedp.eps", ///
	replace)


graph combine "fedl.eps" "fedq.eps" ///
"fedp.eps", ycommon ///
graphregion(color(white)) rows(1) cols(3) xsize(12) ysize(4) iscale(*1.5)

graph export "FigureA2.pdf", replace


********* FIGURE A3 *********

use "census11-all.dta", clear

keep if fage>=fage18 & fage18>=threshold - 9 & fage18<=threshold + 10 & ///
		father_ed !=. & mom_ed != . & fage !=. & mage !=.

keep if relate == 3 & son == 1 & sons == 1 & urban == 2


sort fa
by fa: egen med = mean(mom_ed) if relate==3 & son==1 & sons == 1 & fage>=fage18 & urban == 2 & college_plus !=. & father_ed != . & mom_ed != .& mage !=.
egen mmed = tag(med)

twoway ///
(scatter med fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & urban == 2, mcolor(gs3) ) ///
(lfitci mom_ed fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==1 & urban == 2,fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lfitci mom_ed fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==0 & urban == 2, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) xtitle("Age of the Sole Son's Father") ///
		ytitle("Mother's Education Level") title("Linear fit")  note("") saving("medl.eps", replace)
		
twoway ///
(scatter med fage18, mcolor(gs3)) ///
(qfitci mom_ed fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(qfitci mom_ed fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Mother's Education Level") ///
	title("Quadratic fit")  note("") saving("medq.eps", ///
	replace)

twoway ///
(scatter med fage18, mcolor(gs3)) ///
(lpolyci mom_ed fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lpolyci mom_ed fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) yscale(range(0 1)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Mother's Education Level") ///
	title("Polynomial fit")  note("") saving("medp.eps", ///
	replace)


graph combine "medl.eps" "medq.eps" ///
"medp.eps", ycommon ///
graphregion(color(white)) rows(1) cols(3) xsize(12) ysize(4) iscale(*1.5)

graph export "FigureA3.pdf", replace



********* FIGURE A4 *********

use "census11-all.dta", clear

keep if fage>=fage18 & fage18>=threshold - 9 & fage18<=threshold + 10 & ///
		father_ed !=. & mom_ed != . & fage !=. & mage !=.

keep if relate == 3 & son == 1 & sons == 1 & urban == 2


sort fa
by fa: egen mfage = mean(fage) if relate==3 & son==1 & sons == 1 & fage>=fage18 & urban == 2 & college_plus !=. & father_ed != . & mom_ed != .& mage !=.

twoway ///
(scatter mfage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & urban == 2, mcolor(gs3) ) ///
(lfitci fage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==1 & urban == 2,fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lfitci fage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==0 & urban == 2, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) xtitle("Age of the Sole Son's Father") ///
		ytitle("Father's Age") title("Linear fit")  note("") saving("fagel.eps", replace)
		
twoway ///
(scatter mfage fage18, mcolor(gs3)) ///
(qfitci fage fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(qfitci fage fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Father's Age") ///
	title("Quadratic fit")  note("") saving("fageq.eps", ///
	replace)

twoway ///
(scatter mfage fage18, mcolor(gs3)) ///
(lpolyci fage fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lpolyci fage fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Father's Age") ///
	title("Polynomial fit")  note("") saving("fagep.eps", ///
	replace)


graph combine "fagel.eps" "fageq.eps" ///
"fagep.eps", ycommon ///
graphregion(color(white)) rows(1) cols(3) xsize(12) ysize(4) iscale(*1.5)

graph export "FigureA4.pdf", replace




********* FIGURE A5 *********

use "census11-all.dta", clear

keep if fage>=fage18 & fage18>=threshold - 9 & fage18<=threshold + 10 & ///
		father_ed !=. & mom_ed != . & fage !=. & mage !=.

keep if relate == 3 & son == 1 & sons == 1 & urban == 2

sort fa
by fa: egen mmage = mean(mage) if relate==3 & son==1 & sons == 1 & fage>=fage18 & urban == 2 & college_plus !=. & father_ed != . & mom_ed != .& mage !=.

twoway ///
(scatter mmage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & urban == 2, mcolor(gs3) ) ///
(lfitci mage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==1 & urban == 2,fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lfitci mage fage18 if relate==3 & son == 1 & sons == 1 & fage>=fage18 & t==0 & urban == 2, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) xtitle("Age of the Sole Son's Father") ///
		ytitle("Mother's Age") title("Linear fit")  note("") saving("magel.eps", replace)
		
twoway ///
(scatter mmage fage18, mcolor(gs3)) ///
(qfitci mage fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(qfitci mage fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Mother's Age") ///
	title("Quadratic fit")  note("") saving("mageq.eps", ///
	replace)

twoway ///
(scatter mmage fage18, mcolor(gs3)) ///
(lpolyci mage fage18 if t==1, n(100) fcolor(none) ciplot(rline) clcolor(gs5)) ///
(lpolyci mage fage18 if t==0, n(100) fcolor(none) ciplot(rline) clcolor(gs5)), ///
	xline(58)  legend(off) graphregion(color(white)) ///
	xtitle("Age of the Sole Son's Father") ytitle("Mother's Age") ///
	title("Polynomial fit")  note("") saving("magep.eps", ///
	replace)


graph combine "magel.eps" "mageq.eps" ///
"magep.eps", ycommon ///
graphregion(color(white)) rows(1) cols(3) xsize(12) ysize(4) iscale(*1.5)

graph export "FigureA5.pdf", replace



	
********************************************************************************
*********************************  THE END *************************************
********************************************************************************
